package com.blog.admin.controller;

import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
import com.blog.admin.service.PhotoAlbumService;
import com.blog.common.core.domain.R;
import com.blog.common.core.enums.PathEnum;
import com.blog.common.core.web.domain.AjaxResult;
import com.blog.common.domain.dto.PhotoAlbumDto;
import com.blog.system.api.domain.SysFile;
import com.blog.system.api.feign.RemoteConfigService;
import com.blog.system.api.feign.RemoteFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 * <p>
 * 相册后台控制器
 * </p>
 *
 * @author Valerie
 * @date 2023/4/16
 **/
@RestController
@Slf4j
@Api("相册后台管理")
@RequiredArgsConstructor
public class PhotoAlbumBackController {


    private final PhotoAlbumService photoAlbumService;

    private final RemoteFileService remoteFileService;

    /**
     * 获取相册列表
     *
     * @return {@link AjaxResult}
     */
    @GetMapping("/album/list")
    @ApiOperation("获取相册列表")
    public AjaxResult listPhotoAlbum(){
        return AjaxResult.success(photoAlbumService.listPhotoAlbum());
    }

    /**
     * 修改相册列表
     *
     * @param photoAlbumDto 相册dto
     * @return {@link AjaxResult}
     */
    @PutMapping("/album")
    @ApiOperation(value = "修改相册列表")
    public AjaxResult updatePhotoAlbum(@RequestBody PhotoAlbumDto photoAlbumDto){
        photoAlbumService.updatePhotoAlbum(photoAlbumDto);
        return AjaxResult.success();
    }

    /**
     * 查询相册
     *
     * @param albumId 相册id
     * @return {@link AjaxResult}
     */
    @GetMapping("/album")
    @ApiOperation(value = "查询相册")
    public AjaxResult listPhotoAlbumById(@RequestParam("albumId") Serializable albumId){
        return AjaxResult.success(photoAlbumService.listPhotoAlbum(albumId));
    }

    /**
     * 上传相册封面
     *
     * @param multipartFile 封面
     * @return {@link AjaxResult}
     */
    @PostMapping("/album/images")
    @ApiOperation("上传相册封面")
    public AjaxResult uploadAlbum(@RequestPart("file")MultipartFile multipartFile){
        R<SysFile> sysFileR = remoteFileService.upload(PathEnum.ALBUM, multipartFile);
        return AjaxResult.success(sysFileR.getData());
    }
}
